package com.ap.core.business.message.response.translators.header.impl;

import org.joda.time.LocalDateTime;

import com.ap.core.business.message.domain.translators.BindingMetaData;
import com.ap.core.business.message.response.translators.ResponseMetaData;
import com.ap.core.business.message.response.translators.ResponseTranslator;
import com.ap.core.business.message.response.translators.listener.ResponseListener;
import com.ap.core.common.types.InputMessageType;
import com.ap.core.cxf.jaxb.acknowledgement.MsgHdrType;
import com.ap.core.cxf.jaxb.managemerchant.RegisterMerchantMessageType;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.info.OnBoardingResponseMessageInfo;
import com.ap.core.message.info.RequestMessageInfo;

/**
 * User: Ranjit.Singh
 * implementation class for {@link com.ap.core.business.message.response.translators.ResponseTranslator} to populate {@link com.ap.core.cxf.jaxb.acknowledgement.MsgHdrType}  in response object
 */
public class OnBoardingMerchantRegistrationMsgHdrResponseTranslator implements ResponseTranslator<RequestMessageInfo<RegisterMerchantMessageType> , OnBoardingResponseMessageInfo> {

    /**
     * {@inheritDoc
     */
    @Override
    public void populateResponse(RequestMessageInfo<RegisterMerchantMessageType> request, OnBoardingResponseMessageInfo response, BindingMetaData bindingMetaData, ResponseMetaData metaData, ResponseListener responseListener) throws BusinessFailureException {
    	final InputMessageType inputMessageType = InputMessageType.getMessageType(request.getMsgHdr().getMsgType().name());
    	bindingMetaData.setInputMessageType(inputMessageType);
    	
    	final MsgHdrType msgHdrType = new MsgHdrType();
        msgHdrType.setMsgTimestamp(new LocalDateTime());
        msgHdrType.setMsgType(inputMessageType.getOutputMsgTypeEnum());
        msgHdrType.setOrgReqMsgId(request.getMsgHdr().getMsgId());
        response.setMsgHdr(msgHdrType);
        responseListener.onMessageHeaderResponse(response);
    }


}
